package com.tutor.lzm.function.teacher.act;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.EditText;

import com.tutor.lzm.AppSession;
import com.tutor.lzm.R;
import com.tutor.lzm.activity.BaseActivity;
import com.tutor.lzm.http.BaseResponse;
import com.tutor.lzm.http.HttpClient;
import com.tutor.lzm.http.request.UpdateCharacterRequest;
import com.tutor.syslib.util.MessageTools;
import com.tutor.syslib.util.TextUtil;

/**
 * Created by Admin on 2017/10/10.
 * 添加特长
 */
public class AddCharacterAct extends BaseActivity {
    EditText editText;


    public static void start(Context context, String character) {
        Intent intent = new Intent(context, AddCharacterAct.class);
        if (!TextUtil.isNull(character)) {
            intent.putExtra("character", character);
        }
        context.startActivity(intent);

    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_add_character);
        initTitle("添加特长", "保存", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UpdateCharacter();
            }
        });
        editText = (EditText) findViewById(R.id.editText);
        if (getIntent().hasExtra("character")) {
            String character = getIntent().getStringExtra("character");
            editText.setText(character);
        }


    }

    /**
     * 保存
     */
    private void UpdateCharacter() {
        UpdateCharacterRequest request = new UpdateCharacterRequest();
        request.teacherId = AppSession.getInstance().getUserId();
        String character = editText.getText().toString().trim();
        if (TextUtil.isNull(character)) {
            MessageTools.showToast(this, "请输入特长");
            return;
        }
        request.character = character;
        HttpClient.post(request, new HttpClient.onSuccessListener() {
            @Override
            public void onSuccess(BaseResponse response) {
                MessageTools.showToast(oThis, "保存成功");
                finish();
            }
        }, new HttpClient.onFailListener() {
            @Override
            public void onFail(int code, String msg) {
                MessageTools.showToast(oThis, msg);
            }
        });
    }
}
